import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.display.Sprite;
import flash.ui.Keyboard;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.filters.GlowFilter;
 


import flash.utils.Timer;
import haxe.Timer;
import flash.events.Event;


import Images;  
import Blob;

class MainCharacter extends Character
{
public var stand : Blob; 
public var standLeft : Blob;
public var move1 : Blob;
public var move2 : Blob;
public var move3 : Blob;
public var move1_left : Blob;
public var move2_left : Blob;
public var move3_left : Blob;
public var kneel : Blob;
public var lying : Blob;

public var attackRight : Blob;
public var attackLeft : Blob;
public var attackDown : Blob;


public function new(inPostion:Point,inMoveSpeed:Int,inJumpSpeed:Int,inAttackSpeed:Int,inHealth:Int,inAttackPower:Int)
  {
    super(inPostion,inMoveSpeed,inJumpSpeed,inAttackSpeed,inHealth,inAttackPower);
stand = new Blob(new MainStand(),0,0,46,52,null,null);
CurrentCharacter  = stand;
      move1 = new Blob(new MainRun1(),0,0,56,54,null,null);
      move2 = new Blob(new MainRun2(),0,0,37,54,null,null);
      move3 = new Blob(new MainRun3(),0,0,47,54,null,null);
      standLeft = new Blob(new MainStandLeft(),0,0,46,52,null,null);
      move1_left = new Blob(new MainRunLeft1(),0,0,56,54,null,null);
      move2_left = new Blob(new MainRunLeft2(),0,0,37,54,null,null);
      move3_left = new Blob(new MainRunLeft3(),0,0,47,54,null,null);
      kneel = new Blob (new  MainKneel(),0,0,53,56,null,null);
      lying = new Blob (new  MainOnGround(),0,0,58,40,null,null);

      attackRight = new Blob(new Attack(),0,0,46,40,null,null);
    attackLeft = new Blob(new AttackLeft(),0,0,46,40,null,null);
    attackDown = new Blob(new AttackDown(),0,0,40,46,null,null);
attack = attackRight;
  characterType = "Main";
    
  }

public override function getAttack(mKeyDown:Array<Bool>)
{
  if (mKeyDown[ Keyboard.SPACE ])
  {
    if(attacking > 0)
      {return;}
    if(jumping > 0)
    {
      attacking = 1;
      attackPostion = new Point(postion.x,postion.y+CurrentCharacter.mRect.height);
      attack = attackDown;
    }
    else if(movingRight)
    {
      attacking = 1;
      attackPostion = new Point(postion.x+CurrentCharacter.mRect.width,postion.y);
      attack = attackRight;
    }
    else
    {
      attacking = 1;
      attackPostion = new Point(postion.x-CurrentCharacter.mRect.width,postion.y);
      attack = attackLeft;
    }
  }
}

public override function getCharacter(mKeyDown:Array<Bool>)
{
if(mKeyDown[ Keyboard.RIGHT ])
	{
        if(CurrentCharacter == stand || moving >= 0 && moving < 4)
	    {
		CurrentCharacter = move1;
		moving++;
	    }
        else if(moving >= 4 && moving < 7)
	    {
		  CurrentCharacter = move2;
		  moving++;
	    }
        else if(moving >= 7 && moving < 10)
	    {
		CurrentCharacter = move3;
		moving++;
		if(moving >= 10) 
		{
		    moving = 0;
		}
	    }

	}
else if(mKeyDown[ Keyboard.LEFT ])
{
        if(CurrentCharacter == stand || moving >= 0 && moving < 4)
	    {
		CurrentCharacter = move1_left;
		moving++;
	    }
        else if(moving >= 4 && moving < 7)
	    {
		  CurrentCharacter = move2_left;
		  moving++;
	    }
        else if(moving >= 7 && moving < 10)
	    {
		CurrentCharacter = move3_left;
		moving++;
		if(moving >= 10) 
		{
		    moving = 0;
		}
	    }

}
      else
	{
	moving = 0;
	if(movingRight)
	  {
	  CurrentCharacter = stand;
	  }
	else
	  {
	  CurrentCharacter = standLeft;
	  }
	}
}

}